import Vue from 'vue'
import Router from 'vue-router'
import Cookies from 'js-cookie';  //npm install --save js-cookie
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)
let routers = [
    {
        path: '/',
        name: '首页',
        redirect: { name: 'Login' }
    },
    {
        path: '/Login',
        name: 'Login',
        component: () => import('../view/login/Login.vue'),
    },
    {
        path: '/Login/Home',
        name: 'Home',
        component: () => import('../view/home/Home.vue'),
        children: [
            {
                path: '/Login/EmployeeManagement',
                name: 'EmployeeManagement',
                component: () => import('../view/employee/EmployeeManagement.vue')

            },
            {
                path: '/Login/DepartMent',
                name: 'DepartMent',
                component: () => import('../view/employee/DepartMent.vue')

            },
            {
                path: '/Login/AddEmployee',
                name: 'AddEmployee',
                component: () => import('../view/employee/AddEmployee.vue')

            },
            {
                path: '/Login/GuestManage',
                name: 'GuestManage',
                component: () => import('../view/guest/GuestManage.vue')

            },
            {
                path: '/Login/AddGuest',
                name: 'AddGuest',
                component: () => import('../view/guest/AddGuest.vue')

            },
            {
                path: '/Login/Good',
                name: 'Good',
                component: () => import('../view/report/Good.vue')

            },
            {
                path: '/Login/Room',
                name: 'Room',
                component: () => import('../view/room/Room.vue')

            },
            {
                path: '/Login/RoomHistory',
                name: 'RoomHistory',
                component: () => import('../view/room/RoomHistory.vue')

            },
            {
                path: '/Login/ExpensesDayily',
                name: 'ExpensesDayily',
                component: () => import('../view/account/ExpensesDayily.vue')

            },
        ]
    },

]
var route = new Router({
    routes: routers,
    mode: "history"
})
route.beforeEach((to, from, next) => {
        //debugger
        if (to.path === '/Login') {
          next();
        } else {
          let token = Cookies.get('token');   ///localStorage.getItem('Authorization')
          if (!token) {
            next('/Login');
          } else {
            next();
          }
        }
      });
export default route;


